package util

import (
	"fmt"
	"time"
)

var retryChan chan bool = make(chan bool)

func Retry(f func() bool, rules []int)  {
	retryChan <- f()
	if <-retryChan {
		// 重试成功
		return
	}

	for k, v := range rules {
		fmt.Println("重试次数", k)
		go time.AfterFunc(time.Duration(v) * time.Second, func() {
			retryChan <- f()
		})
		if <-retryChan {
			// 重试成功
			fmt.Println("重试成功")
			return
		}
	}
	//重试次数达到上限，结束执行
	fmt.Println("重试次数达到上限")
	return
}
